<template>
	<view class="dialResult-container">
		<!-- #ifdef MP-WEIXIN -->
		<view class="" style="display: flex;justify-content: flex-end;margin-bottom: 10rpx;">
			<view class="" @tap="dialInfoModal = true" style="font-size: 14px;">拨号须知</view>
		</view>
		<!-- #endif -->
		<view class="dialResult-nav">
			<u-grid :border="false" @click="click" col="4">
				<u-grid-item>
					<text style="color: #000;font-weight: 600;">{{resultList.allLineV4}}</text>
					<text class="grid-text">拨号</text>
				</u-grid-item>
				<u-grid-item>
					<text style="color: #1D93FF;font-weight: 600;">{{resultList.sucLineV4}}</text>
					<text class="grid-text">已拨通</text>
				</u-grid-item>
				<u-grid-item>
					<text style="color: #fe020e;font-weight: 600;">{{resultList.errLineV4}}</text>
					<text class="grid-text">未拨通</text>
				</u-grid-item>
				<u-grid-item>
					<text style="color: #3aa74a;font-weight: 600;">{{resultList.networkLineV4}}</text>
					<text class="grid-text">已联网</text>
				</u-grid-item>
			</u-grid>
		</view>
		<view class="flex-end" style="margin-bottom: 20rpx;font-size: 26rpx;">
			<view class="" style="margin: 0 5rpx;">IPv6:已开启<text
					:style="{color:dialResultColor[0]}">{{resultList.allLineV6}}</text>条</view>/
			<view class="" style="margin: 0 5rpx;">拨通<text
					:style="{color:dialResultColor[2]}">{{resultList.sucLineV6}}</text>条&nbsp;</view>/
			<view class="" style="margin: 0 5rpx;">&nbsp;联网<text
					:style="{color:dialResultColor[2]}">{{resultList.networkLineV6}}</text>条</view>
		</view>
		<view class="dialResult-main">
			<view class="dialInfo-item-box" v-for="(item,index) in resultList.netcards" :key="index">
				<view class="dialInfo-item-nav">
					<view class="nav-left">
						<view class="network">
							<text>网卡：</text>
							<text>{{item.name}}</text>
						</view>
						<view class="rate">
							<text>速率：</text>
							<text>{{item.speed}}M</text>
						</view>
					</view>
				</view>
				<!-- <view class="" style="font-size: 12px;color: #8c8c8c;margin: 10rpx 0;">共{{item.children.length}}条线路</view> -->
				<view class="" style="font-size: 12px;color: #8c8c8c;margin: 10rpx 0;">共{{item.dialingInfo.length}}条线路
				</view>
				<view class="dialInfo-table">
					<view class="tr bg-w">
						<view class="th flex-center" style="width: 20%;">序号</view>
						<view class="th" style="width: 50%;">拨号信息</view>
						<!-- <view class="th" style=""></view> -->
						<view class="th flex-center">拨号结果</view>
					</view>
					<view class="tr" v-for="(val,ind) in item.dialingInfo">
						<view class="td flex-center" style="text-align: center;width: 10%;">{{ind + 1}}</view>
						<view class="td" style="width: 55%;margin: 10rpx 0;">
							<view class="" style="font-size: 26rpx;">{{val.account}}</view>
							<view class="" style="color: #999;font-size: 20rpx;">密码:{{val.password}} | vlan ID:
								{{val.vlanId}}
							</view>
						</view>
						<!-- <view class="td" style="color: #999;width: 25%;"></view> -->
						<!-- <view class="td flex-center" style="text-align: center;color: #1D93FF;">拨号中</view> -->
						<view class="td flex-center" :style="{color:dialResultColor[val.result]}"
							style="text-align: center;font-size: 20rpx;">
							<view class=""
								:style="{fontSize: '24rpx',color:val.successed ? dialResultColor[1] : dialResultColor[2]}">
								{{val.successed ? '已拨通' : '未拨通'}} / {{val.connected ? '已联网' : '未联网'}}
							</view>
							<view class="flex" style="justifyContent: center">
								<text>IPv6:</text>
								<view v-if="val.enableV6"
									:style="{color:val.v6Successed ? dialResultColor[1] : dialResultColor[2]}">
									{{val.v6Successed ? '已拨通' : '未拨通'}} /
									{{val.v6Connected ? '已联网' : '未联网'}}
								</view>
								<view class="" v-else>
									未启用
								</view>
							</view>
							<view class="" v-if="val.successed">IP:{{val.ip}}</view>
							<view class="" :style="{color:dialResultColor[2]}" v-else>注:{{val.failedReason}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="bottom">
			<view class="">
				<u-button type="warning" size="large" customStyle="font-weight:600" color="#1D93FF" text="调整线路"
					@click="handleEditLine"></u-button>
			</view>
			<!-- <view class="">
				<u-button type="warning" size="large" customStyle="font-weight:600" color="#1D93FF" text="开启/关闭IPv6"
					@click="handleIPv6"></u-button>
			</view> -->
			<view class="">
				<u-button type="warning" size="large" customStyle="font-weight:600;color:#515151" color="#dddddd"
					text="同步网卡" @click="handleNetCard"></u-button>
			</view>
		</view>
		<u-modal :show="dialInfoModal" title="拨号须知" @cancel="dialInfoModal = false" @confirm="dialInfoModal = false">
			<view class="">
				<view class="">1.拨号进行中时间为10-15分钟，请耐心等待~</view>
				<view class="">2.拨号信息设置完成后请点击“确认提交等待下发业务，设置完成后请勿随意调整线路!</view>
				<view class="">3.“建议调整时间段:00:00-11:0014:00-17:00，不可随意增减线路数量影响收益”!!</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dialInfoModal: false,
				ids: null,
				resultList: [],
				dialResult: ['拨号中', '拨号成功', '拨号失败'],
				dialResultColor: ['#1D93FF', '#47d95b', '#fd0714'],
				dialNet: ['未联网', '已联网'],
				isTime: 60,
			};
		},
		onLoad(options) {
			this.ids = options.ids
			this.getResult()
		},
		onShow() {
			// this.getResult()
		},
		onNavigationBarButtonTap() {
			this.dialInfoModal = true
		},
		onHide() {
			clearInterval(this.IntervalTime)
		},
		beforeDestroy() {
			clearInterval(this.IntervalTime)
		},
		methods: {
			// 同步网卡信息
			async handleNetCard() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				})
				const res = await this.$fun.ajax.post('bind/syncNetcard', {
					ids: this.ids
				})
				uni.hideLoading()
			},
			handleIPv6() {
				this.$fun.jump(`/pageC/settingIPv6/settingIPv6?ids=${this.ids}`)
			},
			// 确认提交
			handleNext() {
				this.$fun.jump(`/pages/equipment/equipment`)
			},
			// 调整线路
			handleEditLine() {
				this.$fun.jump(`/pageC/dialInfo2/dialInfo2?ids=${this.ids}`)
			},
			// 获取拨号结果
			async getResult() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				})
				const res = await this.$fun.ajax.post('bind/dialingInfo', {
					ids: this.ids
				})
				uni.hideLoading()
				const data = res.data.netcards.filter(item => {
					if (item.isValid && !item.isManager) return item
				})

				this.resultList = {
					...res.data,
					netcards: data
				}
				// const res = await this.$fun.ajax.post('butt/queryDialResult',{sn:this.sn})
				// if(res&&res.code==1){
				// uni.hideLoading()
				// 数据去重
				// let newArr = []
				// res.data.vlanInfoList.forEach((item=>{
				// 	const isFlag = newArr.find(i=>i.ifName == item.ifName)
				// 	if(!isFlag){
				// 		newArr.push(item)
				// 	}
				// }))
				// newArr.forEach((item=>{
				// 	item.children = []
				// 	res.data.vlanInfoList.forEach(v=>{
				// 		if(item.ifName == v.ifName){
				// 			item.children.push(v)
				// 		}
				// 	})
				// }))
				// res.data.nicList = newArr

				// this.resultList = res.data
				// this.isTime = res.data.timingtime
				// if(res.data.timingtime > 0){ 
				// 	this.IntervalTime = setInterval(()=>{
				// 		if(this.isTime<=0){
				// 			clearInterval(this.IntervalTime)
				// 			this.isTime = 60
				// 			this.getResult()
				// 		}
				// 		this.isTime--
				// 	},1000)
				// }

				// }
			},
			click(name) {
				this.$refs.uToast.success(`点击了第${name}个`)
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #EEEEEE;
	}

	.dialResult-container {
		padding: 20rpx;

		.dialResult-nav {
			background-color: #fff;
			padding: 30rpx;
			margin-bottom: 10rpx;
			border-radius: 20rpx;

			.grid-text {
				color: #999;
				font-size: 14px;
			}
		}

		.dialResult-main {
			.dialInfo-item-box {
				margin-bottom: 30rpx;
				padding: 20rpx;
				background-color: #fff;
				border-radius: 10rpx;

				.dialInfo-item-nav {
					display: flex;
					justify-content: space-between;
					font-size: 22rpx;

					.nav-left {
						display: flex;
					}

					.nav-right {
						color: #999;
					}

					.network {
						margin-right: 20rpx;
						color: #1D93FF;
					}

					.rate {}
				}

				.dialInfo-table {
					font-size: 24rpx;

					.tr {
						display: flex;
						width: 100%;
						justify-content: center;
						height: 100rpx;
						align-items: center;
						border-radius: 10rpx;
						margin: 15rpx 0;
					}

					.td {
						width: 40%;
						// justify-content: center;
						// text-align: center;
						overflow: hidden;
						margin: 0 10rpx;
						font-size: 22rpx;
						color: #000;
						;
					}

					.flex-center {
						justify-content: center;
						// text-align: center;
					}

					.th {
						width: 40%;
						color: #000;
						display: flex;
						height: 3rem;
						align-items: center;
						overflow: hidden;
						margin: 0 10rpx;
					}

					.bg-w {
						background: #f0f0f0;
					}

					th {
						font-weight: 500;
					}

					td {
						// font-size: 12px;
					}

					.table-placeholder {
						font-size: 14px;
					}

					.delete {
						.u-icon--right {
							flex-direction: column;
						}
					}
				}
			}
		}

		.bottom {

			// background-color: #fff;
			// height: 120rpx;
			// position: fixed;
			// bottom: 0;
			// left: 0;
			// right: 0;
			// padding: 30rpx; 
			// display: flex;
			// justify-content: space-between;
			&>view {
				margin: 20rpx 0;
			}

		}
	}
</style>